<template>
    <!-- <van-button :icon="value ? 'star-o' : 'star'" ></van-button> -->
    <van-icon :color="value ? '#ffa500' : '#777'" :name="value ? 'star' : 'star-o'" @click="onCollect" />
</template>

<script>
import { addCollect, deleteCollect } from '../api/article'

export default {
    name: 'CollectArticle',
    props: {
        value: {
            type: Boolean,
            required: true
        },
        art_id: {
            type: [String, Number, Object],
            required: true
        }
    },
    methods: {
        async onCollect() {
            try {
                if (this.value) {
                    await deleteCollect(this.art_id)
                } else {
                    await addCollect(this.art_id)
                }
                this.$emit('input', !this.value)
                // setTimeout(() => {
                //     this.$toast.success(this.value ? '收藏成功' : '取消收藏')
                // }, 0)
                this.$nextTick(() => {
                    this.$toast.success(this.value ? '收藏成功' : '取消收藏')
                })
            } catch (err) {
                console.log('收藏失败', err);
                this.$toast.fail('操作失败，请稍后重试')
            }
        }
    }
}
</script>

<style>
</style>